home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
Error.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-21
|
2KB
|
116 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "Error.h"
#include "String.h"
#include "System.h"
#include "Env.h"
static ErrorHandlerFunc errorhandler= DefaultErrorHandler;
ErrorHandlerFunc SetErrorHandler(ErrorHandlerFunc newhandler)
{
ErrorHandlerFunc oldhandler= errorhandler;
errorhandler= newhandler;
return oldhandler;
}
ErrorHandlerFunc GetErrorHandler()
{
return errorhandler;
}
void AbstractMethod(char *s)
{
Warning(s, "abstract method called");
}
void MayNotUse(char *s)
{
Warning(s, "may not use");
}
void DefaultErrorHandler(int level, bool abort, char *location, char *msg)
{
char *type= "Warning";
if (level < Env::GetValue("System.IgnoreLevel", cError))
return;
if (level >= cFatal)
type= "Fatal";
else if (level >= cSysError)
type= "SysError";
else if (level >= cError)
type= "Error";
fprintf (stderr, "%s in <%s>: %s\n", type, location, msg);
fflush (stderr);
if (abort) {
fprintf (stderr, "aborting\n");
fflush (stderr);
gSystem->Abort();
}
}
void ErrorHandler(int level, char *location, char *fmt, va_list ap)
{
char buf[1024], *bp;
vsprintf(buf, fmt, ap);
if (level >= cSysError && level < cFatal)
bp= form("%s (%s)", buf, gSystem->GetError());
else
bp= buf;
errorhandler(level, level >= Env::GetValue("System.AbortLevel", cSysError), location, bp);
}
void Error(char *location, char *va_(fmt), ...)
{
va_list ap;
va_start(ap,va_(fmt));
ErrorHandler(cError, location, va_(fmt), ap);
va_end(ap);
}
void SysError(char *location, char *va_(fmt), ...)
{
va_list ap;
va_start(ap, va_(fmt));
ErrorHandler(cSysError, location, va_(fmt), ap);
va_end(ap);
}
void Warning(char *location, char *va_(fmt), ...)
{
va_list ap;
va_start(ap,va_(fmt));
ErrorHandler(cWarning, location, va_(fmt), ap);
va_end(ap);
}
void Fatal(char *location, char *va_(fmt), ...)
{
va_list ap;
va_start(ap,va_(fmt));
ErrorHandler(cFatal, location, va_(fmt), ap);
va_end(ap);
}
static int gAssertLevel= -1;
int GetAssertLevel()
{
if (gAssertLevel == -1)
gAssertLevel= Env::GetValue("System.AssertLevel", cMaxInt);
return gAssertLevel;
}
int SetAssertLevel(int l)
{
int old= gAssertLevel;
gAssertLevel= l;
return old;
}